﻿<UserControl x:Class="Wizard.WizardControl.Views.WizardView"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
             mc:Ignorable="d"
             xmlns:local="clr-namespace:Wizard.WizardControl"
             xmlns:view="clr-namespace:Wizard.WizardControl.Views"
             xmlns:viewModel="clr-namespace:Wizard.WizardControl.Models">
    <UserControl.Resources>

        <!-- HEADERED CONTENT CONTROL STYLE -->
        <Style TargetType="{x:Type HeaderedContentControl}">
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="{x:Type HeaderedContentControl}">
                        <StackPanel Margin="2,0">
                            <Grid Margin="1,1,1,12"
                                  RenderTransformOrigin="0.5,0.5">
                                <Rectangle Fill="BurlyWood"
                                           Height="3"
                                           Margin="10,0"
                                           Opacity="0.6"
                                           RadiusX="8"
                                           RadiusY="8"
                                           VerticalAlignment="Bottom" />
                                <ContentPresenter ContentSource="Header"
                                                  TextBlock.FontSize="22"
                                                  TextBlock.FontWeight="DemiBold"
                                                  TextBlock.Foreground="Brown"
                                                  HorizontalAlignment="Center"
                                                  VerticalAlignment="Center" />
                                <Grid.Effect>
                                    <DropShadowEffect Opacity="0.1" />
                                </Grid.Effect>
                                <Grid.RenderTransform>
                                    <RotateTransform Angle="-3" />
                                </Grid.RenderTransform>
                            </Grid>
                            <Grid>
                                <Rectangle Fill="{TemplateBinding Background}" />
                                <ContentPresenter ContentSource="Content" />
                            </Grid>
                        </StackPanel>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>

        <!-- WIZARD STEP TEMPLATE -->
        <DataTemplate x:Key="wizardStepTemplate">
            <Border x:Name="bdOuter"
                    BorderBrush="Black"
                    BorderThickness="0,0,1,1"
                    CornerRadius="12"
                    Margin="1,1,1,12"
                    Opacity="0.5"
                    SnapsToDevicePixels="True">
                <Border x:Name="bdInner"
                        Background="#FFFEFEFE"
                        BorderBrush="Brown"
                        BorderThickness="2,2,1,1"
                        CornerRadius="12"
                        Padding="2">
                    <!-- We need a grid here because it defaults to elements stacked directly on top of one another -->
                    <Grid>
                        <TextBlock x:Name="txt"
                                   Margin="4,0,0,0"
                                   Text="{Binding Path=ViewModel.DisplayName}" />
                    </Grid>
                </Border>
            </Border>

            <DataTemplate.Triggers>
                <DataTrigger Binding="{Binding Path=ViewModel.IsCurrentStep}"
                             Value="True">
                    <Setter TargetName="txt"
                            Property="FontWeight"
                            Value="Bold" />
                    <Setter TargetName="bdInner"
                            Property="Background"
                            Value="BurlyWood" />
                    <Setter TargetName="bdOuter"
                            Property="Opacity"
                            Value="1" />
                </DataTrigger>
                <!-- show/hide steps (must be relevant and visited to be visible) -->
                <DataTrigger Binding="{Binding Path=Relevant}"
                             Value="False">
                    <Setter TargetName="bdOuter"
                            Property="Visibility"
                            Value="Collapsed" />
                </DataTrigger>
                <DataTrigger Binding="{Binding Path=Visited}"
                             Value="False">
                    <Setter TargetName="bdOuter"
                            Property="Visibility"
                            Value="Collapsed" />
                </DataTrigger>
            </DataTemplate.Triggers>
        </DataTemplate>

    </UserControl.Resources>

    <Grid Background="Beige"
          Margin="1">
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="200" />
            <ColumnDefinition Width="*" />
        </Grid.ColumnDefinitions>
        <Grid.RowDefinitions>
            <RowDefinition Height="*" />
            <RowDefinition Height="30" />
        </Grid.RowDefinitions>

        <!-- WIZARD STEP LISTING -->
        <HeaderedContentControl Header="Steps">
            <ItemsControl ItemsSource="{Binding Path=Steps}"
                          ItemTemplate="{StaticResource wizardStepTemplate}" />
        </HeaderedContentControl>

        <!-- current step -->
        <Border Background="White"
                Grid.Column="1"
                Grid.Row="0">
            <!--When "content" is set, that sets the DataContext of this element-->
            <HeaderedContentControl Content="{Binding Path=CurrentLinkedListStep.Value.ViewModel}"
                                    Header="{Binding Path=CurrentLinkedListStep.Value.ViewModel.DisplayName}">
                <HeaderedContentControl.Resources>
                    <local:StepTemplateConverter x:Key="stepTemplateConverter" />
                </HeaderedContentControl.Resources>
                <ContentControl.Style>
                    <Style BasedOn="{StaticResource {x:Type HeaderedContentControl}}"
                           TargetType="HeaderedContentControl">
                        <!--This "watches" the value of CurrentLinkedListStep and updates the template (current step xaml) when it changes.
                            So totally and completely seems like it needs a DataTrigger or an EventTrigger, no?
                            Path when referenced this way (by finding ancestor) must include "DataContext"-->
                        <Setter Property="ContentTemplate"
                                Value="{Binding Path=DataContext.CurrentLinkedListStep.Value, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type UserControl}}, Converter={StaticResource stepTemplateConverter}}" />
                    </Style>
                </ContentControl.Style>
            </HeaderedContentControl>
        </Border>


    </Grid>
</UserControl>
